'''
Created on Dec 14, 2011

@author: Box II
'''

import math as m
import htmlAggregator as ha
from mpl_toolkits.basemap import Basemap
import numpy as np



def convertToDaysAfter2004(yearmonthdayStr):
    attr = yearmonthdayStr.split("-")
    yeardiff=0
    monthdiff=0
    dayDiff=0
    
    yeardiff = int(attr[0])-2004
    monthdiff = int(attr[1])
    dayDiff = int(attr[2])
    print yeardiff
    
    result = (yeardiff*365)+(monthdiff*31)+dayDiff
    return result


data1 = []
date1 = []
cto=0
#Word file index + offset
ha = ha.htmlAggregator()
print "Object created, instantiating reader object."
bigassArray=[]
print "Reading."
ha.markStart()
bigassArray=ha.getDir("../../irq/report")
print "Done reading. Entries read: "+str(len(ha.totalArray))
print "Outputting CSV"
kFl= open('outputReduced2004.csv', 'w')
currentYear=2004
titleStr="Date,EVID,Sector,Latitude,Longitude,DateTime,Type,Category,Affiliation,"
titleStr=titleStr+"Enemy Killed , Friendly Killed, Civilian Killed, Host Nation Killed, Enemy Wounded, Friendly Wounded, Civilian Wounded,Host Nation Wounded\n"
kFl.write(titleStr)
    
    
    

for entry in ha.totalArray :
    totalString=""
    eval=entry[0].split("-")
    if int(eval[0])!=currentYear:
        kFl.close()
        print("End Year: Closed...(YEAR)"+str(currentYear))
        currentYear=int(eval[0])
        kFl= open("outputReduced"+str(currentYear)+".csv", 'w')
        print("New year: Changing output vector...(YEAR)"+str(currentYear))
    for subentry in entry:
        totalString=totalString+subentry+","
    totalString = totalString.rstrip(',')
    kFl.write(totalString+"\n")
        
print "Done."
        
        


